<template>
	<view>
		<view class="">
			<!-- 2.0.19支持autoBack，默认为false -->
			<u-navbar leftText="我的订单" :autoBack="true">
			</u-navbar>
		</view>
		
		<view class="con-body wrap">
			<view class="u-tabs-box">
				<u-sticky bgColor="#fff">
				    <u-tabs :list="list" @change="change"></u-tabs>
				  </u-sticky>
			</view>
			
			<view class="page-box">
				
				<view class="order" v-for="(res, index) in orderList" :key="res.id">
					<view class="top">
						<view class="left">
							<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
							<view class="store">订单编号:{{ res.order_no }}</view>
							<!-- <u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon> -->
						</view>
						<view class="right"><text>{{res.status_label}}</text></view>
					</view>
					<view class="item" v-for="(item, index) in res.item" :key="index">
						<view class="left"><image :src="item.goods_cover" mode="aspectFill"></image></view>
						<view class="content">
							<view class="title u-line-2">{{ item.goods_name }}聚合反应附加费几号发货</view>
							<view class="type">{{ item.goods_spec }}</view>
							<view class="delivery-time">更新时间 {{$u.timeFormat(item.update_time, 'yyyy年mm月dd日')}}</view>
						</view>
						<view class="right">
							<view class="price">
								￥{{ priceInt(item.total_selling) }}
								<text class="decimal">.{{ priceDecimal(item.total_selling) }}</text>
							</view>
							<view class="number">x{{ item.stock_sales }}</view>
						</view>
					</view>
					<view class="total">
						共{{ res.number_goods}}件商品 合计:
						<text class="total-price">
							￥{{ res.amount_goods }}.
							<text class="decimal">{{ priceDecimal(res.amount_goods) }}</text>
						</text>
					</view>
					<view class="bottom">
						<view class="more"><u-icon name="more-dot-fill" color="rgb(203,203,203)"></u-icon></view>
						<view class="logistics btn" @click="todetail(res.id)">查看详情</view>
						<!-- <view class="exchange btn">卖了换钱</view> -->
						<!-- <view class="evaluate btn">评价</view> -->
					</view>
				</view>
				<!-- <u-loadmore :status="loadStatus[0]" bgColor="#f2f2f2"></u-loadmore> -->
			</view>
				
			<view class="page-box" v-if="shownull">
				<view>
					<view class="centre">
						<image src="https://resourse.cnlhjt.com/upload/20220827/b8dc4f9e7283587f59b9b0dc805e8737.png" mode=""></image>
						<view class="explain">
							您还没有相关的订单
							<view class="tips">可以去看看有那些想买的</view>
						</view>
						<view class="btn" @click="tomore">随便逛逛</view>
					</view>
				</view>
			</view>
				
		</view>
		<!-- 弹框提示 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import { getOrderList } from "@/service/shopservice.js";
export default {
	data() {
		return {
			page:1,
			limit:10,
			status:0,
			shownull:false,
			orderList: [],
			list: [
				{
					name: '待付款'
				},
				{
					name: '待发货'
				},
				{
					name: '待收货'
				},
				{
					name: '待评价',
					// count: 12
				}
			],
			current: 0,
			tabsHeight: 0,
			dx: 0,
		};
	},
	onLoad() {
		getOrderList({status:99}).then(this.getOrderList);
	},
	onReachBottom() {
		// if (this.status == 'nomore') return;
		// this.status = 'loading';
		this.page = ++this.page;
		getOrderList({
			status:this.status,
			page: this.page,
			limit: this.limit
		}).then(res=>{
				// console.log(res);
				if(res.code==200){
					if(res.result.length==0){
						this.$refs.uToast.show({
							type: 'error',
							title: '没有更多啦',
							icon:false
							// message: e.msg,
						})
					}else{
						let list = res.result;
						list.forEach((item) => {
							this.orderList.push(item);
						})
					}
					
				}else {
					this.$refs.uToast.show({
						type: 'error',
						title: '没有更多啦',
						icon:false
					})
				}
			});
	},
	computed: {
		// 价格小数
		priceDecimal() {
			return val => {
				if (val !== parseInt(val)) return val.slice(-2);
				else return '00';
			};
		},
		// 价格整数
		priceInt() {
			return val => {
				if (val !== parseInt(val)) return val.split('.')[0];
				else return val;
			};
		}
	},
	methods: {
		reachBottom() {
			// 此tab为空数据
			if(this.current != 2) {
				this.loadStatus.splice(this.current,1,"loading")
				setTimeout(() => {
					this.getOrderList(this.current);
				}, 1200);
			}
		},
		tomore(){
			uni.redirectTo({
				url:'/pagesShop/index/index?cut=1',
				delta:2
			})
		},
		// 页面数据
		getOrderList(e) {
			if(e.code==200){
				this.shownull=false;
				this.orderList=e.result;
			}else{
				this.shownull=true;
				this.orderList=[];
			}
		},
		todetail(id){
			uni.navigateTo({
				url:'./orderDetail?id='+id
			})
			
		},
		// tab栏切换
		change(e) {
			// console.log(index)
			let par;
			this.current = e.index;
			switch (this.current) {
				case 0:
					par = {
						status: 0,
					};
					break;
				case 1:
					par = {
						status: 1,
					};
					break;
				case 2:
					par = {
						status: 2,
					};
					break;
				case 3:
					par = {
						status: 3,
					};
					break;
				default:
					par = {
						status: 0,
					};
			}
			getOrderList(par).then(this.getOrderList);
		},
		
	}
};
</script>

<style>
/* #ifndef H5 */
page {
	height: 100%;
	background-color: #f2f2f2;
}
/* #endif */
</style>

<style lang="scss" scoped>
.order {
	width: 95%;
	background-color: #ffffff;
	margin: 20rpx auto;
	border-radius: 20rpx;
	box-sizing: border-box;
	padding: 20rpx;
	font-size: 28rpx;
	.top {
		display: flex;
		justify-content: space-between;
		.left {
			display: flex;
			align-items: center;
			.store {
				width:75%;
				margin: 0 10rpx;
				font-size: 32rpx;
				font-weight: bold;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}
		.right {
			display: inline-block;
			width:100rpx;
			color: $u-warning-dark;
		}
	}
	.item {
		display: flex;
		margin: 20rpx 0 0;
		.left {
			margin-right: 20rpx;
			image {
				width: 200rpx;
				height: 200rpx;
				border-radius: 10rpx;
			}
		}
		.content {
			width:52%;
			.title {
				font-size: 28rpx;
				line-height: 50rpx;
			}
			.type {
				margin: 10rpx 0;
				font-size: 24rpx;
				color: $u-tips-color;
			}
			.delivery-time {
				color: #e5d001;
				font-size: 24rpx;
			}
		}
		.right {
			margin-left: 10rpx;
			padding-top: 20rpx;
			text-align: right;
			.decimal {
				font-size: 24rpx;
				margin-top: 4rpx;
			}
			.number {
				color: $u-tips-color;
				font-size: 24rpx;
			}
		}
	}
	.total {
		margin-top: 20rpx;
		text-align: right;
		font-size: 24rpx;
		.total-price {
			font-size: 32rpx;
		}
	}
	.bottom {
		display: flex;
		margin-top: 40rpx;
		padding: 0 10rpx;
		justify-content: space-between;
		align-items: center;
		.btn {
			line-height: 52rpx;
			width: 160rpx;
			border-radius: 26rpx;
			border: 2rpx solid $u-border-color;
			font-size: 26rpx;
			text-align: center;
			color: $u-info-dark;
		}
		.evaluate {
			color: $u-warning-dark;
			border-color: $u-warning-dark;
		}
	}
}
.centre {
	text-align: center;
	margin: 200rpx auto;
	font-size: 32rpx;
	image {
		width: 164rpx;
		height: 164rpx;
		border-radius: 50%;
		margin-bottom: 20rpx;
	}
	.tips {
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}
	.btn {
		margin: 80rpx auto;
		width: 200rpx;
		border-radius: 32rpx;
		line-height: 64rpx;
		color: #ffffff;
		font-size: 26rpx;
		background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
	}
}
.wrap {
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--window-top));
	width: 100%;
}
.swiper-box {
	flex: 1;
}
.swiper-item {
	height: 100%;
}
</style>
